package guiLayer;

import javax.swing.JPanel;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JTable;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableModel;

import java.awt.ScrollPane;

import javax.swing.JScrollPane;

import net.miginfocom.swing.MigLayout;

import javax.swing.JTextField;

public class OrderMainPanel extends JPanel {

	private JTable table;
	private JTextField txtOrderNo;
	/**
	 * Create the panel.
	 */
	public OrderMainPanel() {
		JButton btnNewButton = new JButton("Udskriv");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		setLayout(new MigLayout("", "[331px,grow][10px][89px]", "[23px][187px][23px]"));
		add(btnNewButton, "cell 0 0,alignx right,aligny top");
		
		JButton btnNewButton_1 = new JButton("Nulstil filtre");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		add(btnNewButton_1, "cell 2 0,growx,aligny top");
		
		txtOrderNo = new JTextField();
		add(txtOrderNo, "cell 0 2,alignx left");
		txtOrderNo.setColumns(10);
		txtOrderNo.getDocument().addDocumentListener(new DocumentListener()
		{

			@Override
			public void changedUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void insertUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void removeUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				
			}
			
		});
		
		
		JButton btnNyOrdre = new JButton("Ny ordre");
		add(btnNyOrdre, "cell 2 2,growx,aligny top");
		btnNyOrdre.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e){
				
			}
		});
		
		JScrollPane scrollPane = new JScrollPane();
		add(scrollPane, "cell 0 1 3 1,grow");
		
		table = new JTable();
		scrollPane.setViewportView(table);
		table.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"Ordrenr.", "Dato", "Medarbejder", "Kunde", "Totalpris", "Betaling", "Pakkes", "Sendes"
			}
		) {
			Class[] columnTypes = new Class[] {
				Integer.class, String.class, String.class, String.class, Double.class, String.class, Boolean.class, Boolean.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
		});
		
		table.getTableHeader().addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent e) {
	        int col = table.columnAtPoint(e.getPoint());
	        String name = table.getColumnName(col);
	        System.out.println("Column index selected " + col + " " + name);
		}
		}
		
				
				);
	}

}
